<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 模拟封装
    /* function fn(item , index , array){
        console.log(item , index , array)
    }

    var list = [2,4,4,6,6,2,,8,7];
    for(var i = 0 ; i < list.length ; i++){
        var item = list[i];
        var index = i;
        var array = list;

        fn(item , index , array);
    } */

    function myEach(list , fn) {
        /* function fn(item, index, array) {
            console.log(item, index, array);
        } */
        /* var fn = function(item , index , array){
            console.log(item, index, array);
        } */

        // var list = [2, 4, 4, 6, 6, 2, , 8, 7];
        for (var i = 0; i < list.length; i++) {
            var item = list[i];
            var index = i;
            var array = list;

            fn(item, index, array);
            console.log(item , index , array);
        }
    }

    var arr = [8 ,9 ,6 ,6];
    var str = "";
    var fn = function(item, index, array){
        str += item;
    }
    myEach(arr , fn);
    console.log(str);


</script>

</html>